package com.m2bshop.shop.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.m2bshop.shop.dao.UserDao;
import com.m2bshop.shop.pojo.User;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/***
 * @date   2022/6/14 0014 9:46
 * @author JackeyTower
 */
@Service
@Transactional(rollbackForClassName = "Exception.class")
public class UserService extends ServiceImpl<UserDao, User>  {
    private UserDao userDao;

    public UserService(UserDao userDao) {
        this.userDao = userDao;
    }

    public User getUserByUsername(String username){
        User user = userDao.selectOne(new QueryWrapper<User>().eq("username",username));
        return user;
    }

    public User getUserByPhonenumber(String phonenumber){
        User user = userDao.selectOne(new QueryWrapper<User>().eq("phonenumber",phonenumber));
        return user;
    }

    public void updateUserByNameTel(User user){
        UpdateWrapper<User> updateWrapper = new UpdateWrapper<>();
        updateWrapper.set("username",user.getUsername());
        updateWrapper.set("phonenumber",user.getPhonenumber());
        updateWrapper.eq("id",user.getId());
        userDao.update(null, updateWrapper);
    }
}
